package com.jhgk.jhcee.app.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jhgk.jhcee.app.domain.model.MSchoolProvinceYearSubjectRecruiteModel;
import com.jhgk.jhcee.common.enums.BasisResultEnum;
import com.jhgk.jhcee.common.resultful.BasisResultful;
import com.jhgk.jhcee.common.resultful.PageResultful;
import com.jhgk.jhcee.jhgk.mapper.MSchoolProvinceYearSubjectRecruiteMapper;
import com.jhgk.jhcee.jhgk.model.MSchoolProvinceYearSubjectRecruite;
import com.jhgk.jhcee.jhgk.model.MSchoolProvinceYearSubjectRecruiteExample;
import com.jhgk.jhcee.app.service.MSchoolProvinceYearSubjectRecruiteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: xiezhongping
 * @description:
 * @date: 2021/8/9 10:36.
 */
@Service(value = "MSchoolProvinceYearSubjectRecruiteServiceImpl")
public class MSchoolProvinceYearSubjectRecruiteServiceImpl implements MSchoolProvinceYearSubjectRecruiteService {

    @Autowired
    MSchoolProvinceYearSubjectRecruiteMapper mSchoolProvinceYearSubjectRecruiteMapper;

    @Override
    public PageResultful<PageInfo<MSchoolProvinceYearSubjectRecruite>> searchAllPage(MSchoolProvinceYearSubjectRecruiteModel model) {
        if (null == model) {
            return PageResultful.fail(BasisResultEnum.PARAM_IS_NULL);
        }
        MSchoolProvinceYearSubjectRecruiteExample example = new MSchoolProvinceYearSubjectRecruiteExample();
        MSchoolProvinceYearSubjectRecruiteExample.Criteria criteria = example.createCriteria();
        criteria.andProvinceUuidEqualTo(model.getProvinceUuid());
        criteria.andYearEqualTo(model.getYear());
        PageHelper.startPage(model.getPage(),model.getLimit());
        List<MSchoolProvinceYearSubjectRecruite> mSchoolProvinceYearSubjectRecruites = mSchoolProvinceYearSubjectRecruiteMapper.selectByExample(example);
        if (mSchoolProvinceYearSubjectRecruites.isEmpty()) {
            return PageResultful.fail(BasisResultEnum.QUERY_IS_NULL);
        }
        return PageResultful.success(new PageInfo<>(mSchoolProvinceYearSubjectRecruites));
    }
}
